import { generate } from '@arco-design/color'

const hexToRgb = (hex: string): string => {
    return (
        parseInt('0x' + hex.slice(1, 3)) +
        ',' +
        parseInt('0x' + hex.slice(3, 5)) +
        ',' +
        parseInt('0x' + hex.slice(5, 7))
    )
}

// 设置主题色
export function setPrimaryColor(hexColor: string) {
    document?.querySelector('body')?.style.setProperty('--arcoblue-1', hexToRgb(generate(hexColor, { index: 1 })))
    document?.querySelector('body')?.style.setProperty('--arcoblue-2', hexToRgb(generate(hexColor, { index: 2 })))
    document?.querySelector('body')?.style.setProperty('--arcoblue-3', hexToRgb(generate(hexColor, { index: 3 })))
    document?.querySelector('body')?.style.setProperty('--arcoblue-4', hexToRgb(generate(hexColor, { index: 4 })))
    document?.querySelector('body')?.style.setProperty('--arcoblue-5', hexToRgb(generate(hexColor, { index: 5 })))
    document?.querySelector('body')?.style.setProperty('--arcoblue-6', hexToRgb(hexColor))
    document?.querySelector('body')?.style.setProperty('--arcoblue-7', hexToRgb(generate(hexColor, { index: 7 })))
    document?.querySelector('body')?.style.setProperty('--arcoblue-8', hexToRgb(generate(hexColor, { index: 8 })))
    document?.querySelector('body')?.style.setProperty('--arcoblue-9', hexToRgb(generate(hexColor, { index: 9 })))
    document?.querySelector('body')?.style.setProperty('--arcoblue-10', hexToRgb(generate(hexColor, { index: 10 })))
}
